<template>
  <div class="menu">
    <template v-for="item in menuList" :key="item.path">
      <template v-if="!item.children">
        <!-- 没有子路由 -->
        <el-menu-item v-if="!item.meta.hidden" :index="item.path">
          <el-icon>
            <component :is="item.meta.icon"></component>
          </el-icon>

          <template #title>
            {{ item.meta.title }}
          </template>
        </el-menu-item>
      </template>

      <template v-if="item.children && item.children.length == 1">
        <!-- 有子路由,但且只有一个 -->
        <el-menu-item
          v-if="!item.children[0].meta.hidden"
          :index="item.children[0].path"
        >
          <el-icon>
            <component :is="item.children[0].meta.icon"></component>
          </el-icon>

          <template #title>
            <span>{{ item.children[0].meta.title }}</span>
          </template>
        </el-menu-item>
      </template>

      <template v-if="item.children && item.children.length > 1">
        <!-- 有子路由且个数大于一个 -->
        <el-sub-menu
          :index="item.path"
          v-if="!item.meta.hidden"
          popper-class="test"
        >
          <template #title>
            <el-icon>
              <component :is="item.meta.icon"></component>
            </el-icon>
            <span>{{ item.meta.title }}</span>
          </template>
          <!-- 递归组件必须要有文字 -->
          <Menu :menuList="item.children"></Menu>
        </el-sub-menu>
      </template>
    </template>
  </div>
</template>

<script lang="ts" setup>
import Menu from "../menu/index.vue";
// 获取父组件传递过来的全部路由数组
defineProps(["menuList"]);
</script>

<style lang="scss">
.test ul {
  background-color: orange;
}
</style>
